
<template>
    <a-row>
        <a-input-search v-model:value="searchKey" placeholder="请输常规仪器串信息" enter-button="搜索"
            style="width: 250px; margin-bottom: 10px;" @search="onSearch()" />
        <a-button style="margin-left: 10px;" type="dashed" @click="reset">重置</a-button>
        <a-space>
            <a-select v-model:value="combinationType" placeholder="选择仪器系列"
                style="width: 150px; margin-bottom: 10px; margin-left: 50px;">
                <a-select-option v-for="(item, index) of instrumentData" :value="item" :key="index">{{ item
                }}</a-select-option>
            </a-select>
        </a-space>
    </a-row>

    <a-table :dataSource="dataSource" size="small" :columns="columns" bordered :scroll="{ x: 1000 }" :pagination="false">
        <template #name="text">
            <a-radio v-model="selectedRowKeys" :value="text">{{ text }}</a-radio>
        </template>
        <template #bodyCell="{ column, text, record }">
            <template v-if="column.title === '仪器串组合'">
                {{ record.instrumentNameList.toString().replace(/,/g, " + ") }}
            </template>
            <template v-if="column.title === '操作'">
                <a-button type="link" @click="choose(record)">选择此行</a-button>
            </template>
        </template>

    </a-table>
    <AntdZh>
        <a-pagination v-model:current="query.pageNum" v-model:pageSize="query.pageSize" :total="total" @change="getList" />
    </AntdZh>
</template>
<script setup>
import { instrumentList } from '../../tool/craft'
import { queryList } from "@/api/tool/combination.js";
import useApp from "@/hooks";
const { $, proxy } = useApp();
const instrumentDatas = ref(instrumentList)
const instrumentData = Object.values(instrumentDatas.value).map(item => item.name)
const emit = defineEmits(["combSuggestSelection"]);
const instrumentType = ref('')
const data = reactive({
    form: {}
});
const { form } = toRefs(data);
const combinationType = ref('')
const dataSource = ref([]);
const total = ref(1)
// 定义表格列配置
const columns = ref([
    {
        title: '仪器串名称',
        dataIndex: 'combinationName',
        key: 'combinationName',
        width: '15%',
    },
    {
        title: '仪器串系列',
        dataIndex: 'combinationSeries',
        key: 'combinationSeries',
        width: '10%',
    },
    {
        title: '作业类别',
        dataIndex: 'combinationType',
        key: 'combinationType',
        width: '10%',
    },
    {
        title: '仪器串组合',
        dataIndex: 'nameList',
        key: 'nameList',
        width: '55%',
    }, {
        title: '操作',
        width: '10%',
    }
])
const searchKey = ref();
const query = ref({ pageNum: 1, pageSize: 10, sortBy: 'id', order: 'ASC', combinationSeries: undefined });
watch(() => combinationType.value, (newVal) => {
    console.log('combinationType.value', newVal)
    getList()
})

function choose(item) {
    emit("combSuggestSelection", item)
}
/** 查询仪器串列表 */
function getList() {
    if (combinationType.value == 'CPLog') {
        query.value.combinationSeries = 'CPLog'
        queryList(query.value).then((response) => {
            dataSource.value = response.content;
            total.value = response.totalElements;
        });
    } else if (combinationType.value == 'ECLIPS-5700') {
        query.value.combinationSeries = '5700'
        queryList(query.value).then((response) => {
            dataSource.value = response.content;
            total.value = response.totalElements;
        });
    } else if (combinationType.value == 'LOGIQ') {
        query.value.combinationSeries = 'LOGIQ'
        queryList(query.value).then((response) => {
            dataSource.value = response.content;
            total.value = response.totalElements;
        });
    } else if (combinationType.value == 'MAXIS-500') {
        query.value.combinationSeries = 'MAXIS-500'
        queryList(query.value).then((response) => {
            dataSource.value = response.content;
            total.value = response.totalElements;
        });
    } else {
        queryList(query.value).then((response) => {
            console.log(response);
            dataSource.value = response.content;
            total.value = response.totalElements;
        });
    }
}
getList();

/** 搜索按钮操作 */
function onSearch() {
    query.value.searchKey = searchKey;
    getList();
}

/** 表单重置 */
function reset() {
    searchKey.value = '';
    combinationType.value = ''
    query.value = {
        pageNum: 1, pageSize: 10, sortBy: 'id',
        searchKey: '',
        combinationSeries: undefined
    }
    getList();
}

/** 提交按钮 */
function submitItem() {

}
</script>
  